//引入组件库
var do_Page = sm("do_Page");
var do_App = sm("do_App");
var nf = sm("do_Notification");
var userUrl = require("url/user");
var http = require("helper/http");
var openHelper = require("helper/open");
var userUtil = require("helper/user");
var hashdata = mm("do_HashData");
var listview = ui("listView");
var listdata = mm("do_ListData");
listview.bindItems(listdata);

var rootview = ui("$");
var noData = [{"template":1,"labelContent":"您还没有好友申请"}];

/****************处理页面-头部-begin*****************/
var headerAout = ui("headerAout");
var addheader = headerAout.add("header", "source://view/reuse/header.ui", 0, 0);

//左上角-返回
var headerLeft = ui(addheader+".headerLeft");
headerLeft.on("touch", function() {
	do_App.closePage();
});

var header = ui("header");
header.bindData(hashdata);
hashdata.addData({"labelTitle" : "新的好友"});
header.refreshData();

/*
//右上角
var headerRight = ui(addheader+".headerRight");
var headerRight_lableNext = ui(addheader+".labelNext");
headerRight_lableNext.text = "确定";
headerRight_lableNext.visible = true;

var menus=[{"template" : 0,"menuIcon":"source://image/menu/useradd.png","menuName" : "邀请新成员","type":"XXXXX"}];
var popmenu = rootview.add("menupop", "source://view/reuse/menu/menu.ui", 0, 0);
var popmenuf = ui("menupop");
headerRight.on("touch", function() {
	popmenuf.fire("popmenuSJ", menus);
});
//点击菜单选项
popmenuf.on("popmenuItem", function(data) {
	var touchIndex = parseInt(data);
	var actionType = menus[touchIndex].type;
	if(actionType=="XXXX"){
		
	}
	popmenuf.fire("popmenuClose");
});
*/

/****************处理页面-头部-end*****************/
// 当前页码
var page = 1;
// 本页面-ajax业务请求url
var httpUrl = userUrl.url.friendApply.newFriends;

// 全部刷新数据
function binddata() {
	page = 1;
	var params = {page : page}
	http.post(httpUrl, params, function(data) {
		listview.rebound();
		listdata.removeAll();// 清除数据
		if (data.friendApplyPage) {
			if(data.friendApplyPage.content.length){
				listdata.addData(data.friendApplyPage.content);
			}else{
				listdata.addData(noData);
			}
			listview.refreshItems();// 刷新item数据
		}
	});
}

function getNextPageData() {
		page++;
		var params = {
			page : page
		}
		http.post(httpUrl, params, function(data) {
			if (data.friendApplyPage) {
				listview.rebound();
				listdata.addData(data.friendApplyPage.content);
				listview.refreshItems();
			}
		});
}

// 下拉列表，刷新数据
listview.on("pull", function(data) {
	if (data.state == 2) {
		binddata();
		listview.rebound();//复位【一定要做】
	}
});

// 上拉列表，翻页数据
listview.on("push", function(data) {
	if (data.state == 2) {
		getNextPageData();
		listview.rebound();//复位【一定要做】
	}
});
//页面装载完成后，开始初始化工作
do_Page.on("loaded", function(){
	binddata();
});
do_Page.on("back", function() {
	do_App.closePage();
});

do_Page.on("new_friend_reflash", function() {
	binddata();
});


